/*
-----------------------------------------------------------------------------
This source file is part of Labor3D
(Labor 3D Graphics Engine)

Copyright (c) 2009-2020 Rock Mao
* creator : Rock Mao
* created : 2009-9-20   22:29
* filename: LaborD3D10FileTexture.h
-----------------------------------------------------------------------------
*/

#ifndef __LABORD3D10FILETEXTURE_H__
#define __LABORD3D10FILETEXTURE_H__
#include "LaborD3D10Def.h"
#include "Renderer\LaborHardwareBuffer.h"
#include "LaborD3D10Headers.h"
#include "LaborD3D10Texture.h"
NAMESPACE_LABOR3D_BEGIN

class CLD3D10FileTexture : public CLD3D10BasicTexture
{
	ID3D10Texture1D *m_p1DTex;
	// 2D texture pointer
	ID3D10Texture2D *m_p2DTex;
	/// cubic texture pointer
	ID3D10Texture3D	*m_p3DTex;	
	/// actual texture pointer
	ID3D10Resource 	*m_pTexture;	
	ID3D10ShaderResourceView*  m_pShaderResourceView;
	D3D10_SHADER_RESOURCE_VIEW_DESC m_srvDesc;
	//CX2DImage::IMAGE_FORMAT m_ImageFormat;

	wstring                    m_FileName;
	char*                      m_pFileBuffer;
	int                        m_pFileBufferLen;


	//CX2DImage*              m_pImage;


protected:
	void                    __uploadTexture();
	void                    __unloadImageCopy();
	void                    __unloadFileBuffer();
	void                    __unloadTexObject();
	bool                    __d3dxLoadTexture();
	bool                    __loadTextureUseXImage(bool bLoadGopy);
	bool                    __loadTGA(bool bLoadGopy);
	bool                    __loadDDS(bool bLoadGopy);
	bool                    __loadFileBuffer(const wchar_t* filename, const char* buf, int len);
	bool                    loadTexture(bool bLoadGopy);

public:
	~CLD3D10FileTexture();
	CLD3D10FileTexture(CLD3D10RenderSystem* pRenderer);
	bool                       onDeviceLost(bool bDeviceChange);


	//=========================================================
	void                       viewPort2ImageCoord(float vx , float vy , float& ix , float& iy);

	CLTexture*                 clone(bool bMultTex){return NULL;}
	bool                       isFlipY(){return m_bFlipY;}
	void                       setFlipY(bool bFlip){ m_bFlipY = bFlip; }
	int                        getHandle(int iLayer = 0){if(iLayer!=0) return 0 ;return (int)m_pShaderResourceView;}
	bool                       getImageSize(int& w , int& h);
	bool                       saveToFile(const char* file,eLPIXEL_FORMAT fmt = eL_PF_None){return false;}

	void                       getUVRange(float& minx , float& miny , float& maxx , float& maxy);

	bool                       getPixel(int x , int y , CLColor_4f& _cl);
	bool                       getDim(sTexSize_t& size);
	eLPIXEL_FORMAT        getFormat() ;
	void*                      lock( SURF_LOCK_INFO & lockinfo);
	void*                      update(void* data  , bool directly ){return NULL;}
	bool                       validate();
	void*                      lockRect( SURF_LOCK_INFO & lockinfo , int x , int y , int w , int h);
	void                       unlock();

	bool                       create(int x , int y , eLPIXEL_FORMAT pixel_format ){	return false;}
	bool                       destory(){ return unload(); }; 

	bool                       load(const wchar_t* filename, eLaborTexLoadArg arg = eLoad_Normal);
	bool                       load(const wchar_t* filename, const char* buf, int len, eLaborTexLoadArg arg = eLoad_Normal);

	int                        getResSize();
	bool                       unload();
	ID3D10ShaderResourceView*  getTexLayer(int iLayer = 0 ){return m_pShaderResourceView;}
	int                        nTexLayer(){return 1;}
protected:
	void                       _create1DTexture();
	void                       _create2DTexture();
	void                       _create3DTexture();
	void                       _createShaderResourcesImpl(void);
};

NAMESPACE_LABOR3D_END

#endif //__LABORD3D10FILETEXTURE_H__